<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/icon.css" />

<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.9.1.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
<title>老师个人信息</title>
</head>
<script type="text/javascript">
$(function() {
	$("#teacherxinxi").datagrid({
		url:'teacherxinxi.json',
		columns:[[    
		          {field:'tid',title:'工号',width:100},    
		          {field:'tname',title:'姓名',width:100},    
		          {field:'tsex',title:'性别',width:100},    
		          {field:'tage',title:'年龄',width:100},    
		          {field:'address',title:'地址',width:100},    
		          {field:'tpnumber',title:'联系电话',width:100}
		      ]] ,
		      toolbar: [{
		    	    	iconCls:'icon-edit',
		    	    	text:'修改个人信息',
		    			handler: function(){
		    				
		    				$('#cc').combobox({  
    						    panelHeight:50
    						}); 
    						
		    						$("#uptTeacher").dialog("open").dialog('setTitle', '修改个人信息');
		    						var arr = $("#teacherxinxi").datagrid('getData');
		    						$("#tname").val(arr.rows[0].tname);
		    						$('#tage').numberbox('setValue', arr.rows[0].tage);
		    						$("#address").val(arr.rows[0].address);
		    						$('#tpnumber').numberbox('setValue', arr.rows[0].tpnumber);

		    				
		    						$("#sve").linkbutton({
		    							onClick:function(){						
		    								var tname = $("#tname").val();
		    								var tage = $('#tage').numberbox('getValue');
		    								var tsex = ($('#cc').combobox('getText'));
		    								var address = $("#address").val();
		    								var tpnumber =  $('#tpnumber').numberbox('getValue');
		    								
		    								var tid =arr.rows[0].tid;
		    								$.ajax({
		    									url:'uptTeacher',
		    									type:'post',
		    									data:{'tid':tid,'tname':tname,'tage':tage,'tsex':tsex,'address':address,'tpnumber':tpnumber},
		    									dataType:'text',
		    									success:function(xx){
		    									if(xx=="0"){
		    										$.messager.alert('error','修改失败！','info');
		    									}else{
		    										$.messager.alert('信息','修改成功','info');	
		    										$("#uptTeacher").dialog("close");		
		    					     				$('#teacherxinxi').datagrid('reload');
		    									}
		    							}
		    						})
		    							}
		    						})
		    				}
		    		}]
	});
	//判断年龄在0——150之间
	$("input",$("#tage").next("span")).blur(function(){
		var tage = $('#tage').numberbox('getValue');
		if(tage<=0||tage>=150){
		    	$("#rtage").show();
		}else{
			$("#rtage").hide();
		}
	    });
	//判断电话号码是否正确
	$("input",$("#tpnumber").next("span")).blur(function(){
		var tpnumber =  $('#tpnumber').numberbox('getValue');
		if(tpnumber<=10000000000||tpnumber>=19999999999){
		    	$("#rtpnumber").show();
		}else{
			$("#rtpnumber").hide();
		}
	    })
	
})
</script>
<body>
<table id="teacherxinxi" >
</table> 
<!------------------------------------- 修改窗口----------------------------------------->
<div id="uptTeacher" class="easyui-dialog"  closed="true" buttons="#dlg1-buttons "  > 
		<div  style="width: 300px;height: 250px;margin-top: 50px;margin-left:80px">
              姓名<input id="tname" name="tname" class="easyui-validatebox"  /><br>    
              年龄<input id="tage" name="tage"  class="easyui-numberbox"  data-options="precision:0"/>
		<span id="rtage"  style="font-size:xx-small;display:none;">年龄在0——150岁之间!</span>
<br>
              性别<select id="cc" class="easyui-combobox" name="tsex" style="width:70px;">   
    <option >男</option>   
    <option>女</option> 
</select><br>
               地址<input id="address" name="address" class="easyui-validatebox"  /><br>
               电话<input id="tpnumber" name="tpnumber" class="easyui-numberbox"  data-options="precision:0" />
               <span id="rtpnumber"  style="font-size:xx-small;display:none;">请输入正确的电话号码!</span> <br>
      </div>
       <div id="dlg1-buttons">
        <button id="sve"  class="easyui-linkbutton"  iconcls="icon-save">确认修改</button>
        <a id="cancl" class="easyui-linkbutton" onclick="javascript:$('#uptTeacher').dialog('close')"
         iconcls="icon-cancel">取消</a>
        </div>
</div>

</body>
</html>